package com.ld.bisystem;


import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;

@MapperScan("com.ld.bisystem.modules.*.dao")
@SpringBootApplication
public class BiSystemApplication {

	/**
	 * 分页插件
	 */
	@Bean
	@ConditionalOnMissingBean
	public PaginationInterceptor paginationInterceptor() {
		return new PaginationInterceptor();
	}

	/**
	 * sql注入器  逻辑删除插件
	 * @return
	 */
	@ConditionalOnMissingBean
	@Bean
	public ISqlInjector iSqlInjector(){
		return new LogicSqlInjector();
	}

	/**
	 * sql性能分析插件，输出sql语句及所需时间
	 * @return
	 */
	@Bean
	@Profile({"dev","test"})// 设置 dev test 环境开启
	@ConditionalOnMissingBean
	public PerformanceInterceptor performanceInterceptor() {
		return new PerformanceInterceptor();
	}
	/**
	 * 乐观锁插件
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean
	public OptimisticLockerInterceptor optimisticLockerInterceptor(){
		return new OptimisticLockerInterceptor();
	}

	public static void main(String[] args) {
		SpringApplication.run(BiSystemApplication.class, args);
	}

}
